<html>
<head><meta charset="utf-8"><title>Unclear error message in where and GATs · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unclear.20error.20message.20in.20where.20and.20GATs.html">Unclear error message in where and GATs</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="248649420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unclear%20error%20message%20in%20where%20and%20GATs/near/248649420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John-John Tedro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unclear.20error.20message.20in.20where.20and.20GATs.html#248649420">(Aug 06 2021 at 18:25)</a>:</h4>
<p>This with <code>where</code> clauses as is coming with <code>generic_associated_types</code>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(generic_associated_types)]</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Collection</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Iter</span>: <span class="nb">IntoIterator</span> <span class="nc">where</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="bp">Self</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Collection</span><span class="o">&gt;</span>::<span class="n">Iter</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nb">IntoIterator</span><span class="o">&gt;</span>::<span class="n">Item</span>: <span class="nc">std</span>::<span class="n">fmt</span>::<span class="n">Debug</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Gives this somewhat unapproachable (and maybe wrong?) error message:</p>
<div class="codehilite"><pre><span></span><code>error[E0277]: the trait bound `&lt;Self as Collection&gt;::Iter: IntoIterator` is not satisfied
 --&gt; src/lib.rs:5:5
  |
5 |     type Iter: IntoIterator where &lt;&lt;Self as Collection&gt;::Iter as IntoIterator&gt;::Item: std::fmt::Debug;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `IntoIterator` is not implemented for `&lt;Self as Collection&gt;::Iter`
  |
help: consider further restricting the associated type
  |
3 | trait Collection where &lt;Self as Collection&gt;::Iter: IntoIterator {
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `&lt;Self as Collection&gt;::Iter: IntoIterator` is not satisfied
   --&gt; src/lib.rs:5:16
    |
5   |       type Iter: IntoIterator where &lt;&lt;Self as Collection&gt;::Iter as IntoIterator&gt;::Item: std::fmt::Debug;
    |                  ^^^^^^^^^^^^ the trait `IntoIterator` is not implemented for `&lt;Self as Collection&gt;::Iter`
    |
help: consider further restricting the associated type
    |
3   | trait Collection where &lt;Self as Collection&gt;::Iter: IntoIterator {
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to 2 previous errors
</code></pre></div>
<p>Lifting the where clause to the trait works as expected which is essentially what you get by working through the hints.</p>
<p>Is this intentionally not supported yet, am I not understanding the scope of this new where syntax, or is this an issue?</p>



<a name="248650146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unclear%20error%20message%20in%20where%20and%20GATs/near/248650146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John-John Tedro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unclear.20error.20message.20in.20where.20and.20GATs.html#248650146">(Aug 06 2021 at 18:30)</a>:</h4>
<p>Also worth noting that the initial issue I had was that I was unable to add the constraint with a GAT, and at that point I'm not sure it would be possible to lift it to the trait's <code>where</code> due to the generic argument not being visible:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(generic_associated_types)]</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Collection</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Iter</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span>: <span class="nb">IntoIterator</span> <span class="nc">where</span><span class="w"> </span><span class="o">&lt;</span><span class="bp">Self</span>::<span class="n">Iter</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nb">IntoIterator</span><span class="o">&gt;</span>::<span class="n">Item</span>: <span class="nc">std</span>::<span class="n">fmt</span>::<span class="n">Debug</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="248665506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unclear%20error%20message%20in%20where%20and%20GATs/near/248665506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John-John Tedro <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unclear.20error.20message.20in.20where.20and.20GATs.html#248665506">(Aug 06 2021 at 20:38)</a>:</h4>
<p>Opened the following issue after probing a bit more with people on Discord: <a href="https://github.com/rust-lang/rust/issues/87831">https://github.com/rust-lang/rust/issues/87831</a></p>



<a name="248665753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Unclear%20error%20message%20in%20where%20and%20GATs/near/248665753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Unclear.20error.20message.20in.20where.20and.20GATs.html#248665753">(Aug 06 2021 at 20:40)</a>:</h4>
<p>Thanks :) Haven't really gotten a chance to look at this or think about it, but an issue is definitely the right place to make sure this doesn't get overlooked</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>